// pages/culture/culture.js
const app = getApp();

import util from '../../utils/util'
import {
  GetMenu,
  GetSlideMobile,
  ServiceList,
  ColumnContent,
  SixColumn,
  GetLevelHomeList,
  HomeScoreList
} from '../../config/api'

Page({

  /**
   * 页面的初始数据
   */
  data: {
    menus:[],
    sliderImgs: [],
    page: 1,
    limit: 10,
    service_list: [],
    expert: '',
    sixList: [],
    starFmailySort: [],
    expertCon: '',
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.getBanner();
    this.getMenu();
    this.getServiceList();
    this.getExpert();
    this.getSixColumn();
    this.getFamilyList();
  },

  getBanner() {
    let that = this;
    util.apiRequest(GetSlideMobile, {
      type: 2,
      vollege_id: app.globalData.vollege_id
    }, null).then(r => {
      console.log("111轮播图数据：", r.data.data);
      that.setData({
        sliderImgs: r.data.data,
      });

    }); //获取首页轮播图图片
  },

  getMenu() { // 获取菜单
    let that = this;
    let params = {
      vollege_id: app.globalData.vollege_id,
      belongs: 5
    }
    util.apiRequest(GetMenu, params, null).then(r => {
      console.log('菜单：', r)
      that.setData({
        menus: r.data.data
      })
    })
  },

  getServiceList() {
    let that = this;
    let params = {
      vollege_id: app.globalData.vollege_id,
      page: this.data.page,
      limit: this.data.limit
    }
    util.apiRequest(ServiceList, params, null).then(r => {
      console.log('服务列表', r)
      that.setData({
        service_list: r.data.data.data
      })
    })
  },

  getExpert() {
    let that = this;
    util.apiRequest(ColumnContent, {
      type: 'expert',
      vollege_id: app.globalData.vollege_id
    }, null).then(r => {
      console.log('专家团队', r)
      if (r.data.data.data.length != 0) {
        that.setData({
          expertCon: r.data.data.data[0].content,
          expert: r.data.data.data[0].content.replace(/\<img/gi, '<img class="rich-img" ')
        })
      }
    })
  },

  getSixColumn() {
    let that = this;
    util.apiRequest(SixColumn, {
      vollege_id: app.globalData.vollege_id
    }, null).then(r => {
      console.log('六：', r)
      that.setData({
        sixList: r.data.data
      })
    })
  },

  getFamilyList() {
    let that = this;
    let y = new Date().getFullYear(); //当前系统年份

    util.apiRequest(HomeScoreList, {
      year: y,
      vollege_id: app.globalData.vollege_id
    }, null).then(r => {
      console.log('家庭；', r.data.data);
      that.setData({
        starFmailySort: r.data.data.data
      })

    });
  },

  toSixList(e) {
    let id = e.currentTarget.dataset.id;
    wx.navigateTo({
      url: '/pages/news/news?id=' + id,
    })
  },

  toDetail: function (e) {
    console.log('eee', e)
    let id = e.currentTarget.dataset.id;
    let status = e.currentTarget.dataset.status;
    if (status == 1 || status == 4) {
      wx.navigateTo({
        url: '/pages/culture/unsolved/unsolved?id=' + id,
      })
    } else {
      wx.navigateTo({
        url: '/pages/culture/resolved/resolved?id=' + id,
      })
    }
  },

  /**
   * 跳转到积分详情页面
   */
  toScoreDetail: function (e) {
    console.log('跳转到积分详情页面！', e.currentTarget.dataset['id']);
    console.log('跳转到积分详情页面code！', e.currentTarget.dataset['code']);
    wx.navigateTo({
      url: '/pages/integralBank/StarFamilyDetailPage/StarFamilyDetailPage?id=' + e.currentTarget.dataset['id'] + '&code=' + e.currentTarget.dataset['code']
    });
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})